﻿using SinavSistemi.Class;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SinavSistemi
{
    public partial class sinav : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["userID"] != null)
	{
		    SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("select * from kullanicilar where userID=@uid",sqlcon);
            sqlcmd.Parameters.AddWithValue("@uid", Request.QueryString["userID"]);

            sqlcon.Open();
            SqlDataReader sdr = sqlcmd.ExecuteReader();
            while (sdr.Read())
            {
                lblAdSoyad.Text = sdr["adsoyad"].ToString();
                lblFirma.Text = sdr["firmaID"].ToString();
                lblEmail.Text = sdr["email"].ToString();
                
            }

            sqlcon.Close();

	}

            if (Request.QueryString["sinavID"] != null)
            {

                SqlConnection sqlcon = connection.baglanti;
                SqlCommand sqlcmd = new SqlCommand("select * from   sinavlar where sinavID=@sinavID",sqlcon);
                sqlcmd.Parameters.AddWithValue("@sinavID",Request.QueryString["sinavID"]);
                sqlcon.Open();
                SqlDataReader sdr = sqlcmd.ExecuteReader();
                if (sdr.Read())
                {
                    lblSinavismi.Text = sdr["sinavismi"].ToString();

                }
                sqlcon.Close();
                 if (Request.QueryString["soruID"] != null)
            {
                SqlCommand sqlcmd2 = new SqlCommand("select * from sorular where soruID=@soruID and sinavID=@sinavID",sqlcon);
                sqlcmd2.Parameters.AddWithValue("@soruID", Request.QueryString["soruID"]);
                sqlcmd2.Parameters.AddWithValue("@sinavID", Request.QueryString["sinavID"]);
                sqlcon.Open();
                SqlDataReader sdr2 = sqlcmd2.ExecuteReader();
                
                if (sdr2.Read())
                {
                    hdresimdurum.Value = sdr2["fotoyolu"].ToString();
                    lblSoru.Text = sdr2["soru"].ToString();
                    sec1.Text = sdr2["sec1"].ToString();
                    sec2.Text = sdr2["sec2"].ToString();
                    sec3.Text = sdr2["sec3"].ToString();
                    sec4.Text = sdr2["sec4"].ToString();
                }

            }


                 sqlcon.Close();
            }

           


        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sinavID =Request.QueryString["sinavID"];
            Session["sinavID"] = sinavID;

            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("update uygulanamalar set durum=1 where sinavID=@sinavID and userID=@userID",sqlcon);
            sqlcmd.Parameters.AddWithValue("@sinavID",sinavID);
            sqlcmd.Parameters.AddWithValue("@userID", Session["userID"]);

            sqlcon.Open();
            sqlcmd.ExecuteNonQuery();

            sqlcon.Close();

            Response.Redirect("sonuc.aspx");


        }
       
        protected void sec1_CheckedChanged(object sender, EventArgs e)
        {
            string soruID = Request.QueryString["soruID"];
            string sinavID = Request.QueryString["sinavID"];
            string userID = Session["userID"].ToString();

            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("update cevaplar set cevap=@cevap where soruID=@soruID and sinavID=@sinavID and userID=@userID",sqlcon);
            sqlcmd.Parameters.AddWithValue("@cevap", sec1.Text );
            sqlcmd.Parameters.AddWithValue("@soruID",soruID);
            sqlcmd.Parameters.AddWithValue("@sinavID",sinavID);
            sqlcmd.Parameters.AddWithValue("@userID",userID);

            sqlcon.Open();

            sqlcmd.ExecuteNonQuery();

            sqlcon.Close();

        }

        protected void sec2_CheckedChanged(object sender, EventArgs e)
        {
            string soruID = Request.QueryString["soruID"];
            string sinavID = Request.QueryString["sinavID"];
            string userID = Session["userID"].ToString();

            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("update cevaplar set cevap=@cevap where soruID=@soruID and sinavID=@sinavID and userID=@userID", sqlcon);
            sqlcmd.Parameters.AddWithValue("@cevap", sec2.Text);
            sqlcmd.Parameters.AddWithValue("@soruID", soruID);
            sqlcmd.Parameters.AddWithValue("@sinavID", sinavID);
            sqlcmd.Parameters.AddWithValue("@userID", userID);

            sqlcon.Open();

            sqlcmd.ExecuteNonQuery();

            sqlcon.Close();

        }

        protected void sec3_CheckedChanged(object sender, EventArgs e)
        {
            string soruID = Request.QueryString["soruID"];
            string sinavID = Request.QueryString["sinavID"];
            string userID = Session["userID"].ToString();

            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("update cevaplar set cevap=@cevap where soruID=@soruID and sinavID=@sinavID and userID=@userID", sqlcon);
            sqlcmd.Parameters.AddWithValue("@cevap", sec3.Text);
            sqlcmd.Parameters.AddWithValue("@soruID", soruID);
            sqlcmd.Parameters.AddWithValue("@sinavID", sinavID);
            sqlcmd.Parameters.AddWithValue("@userID", userID);

            sqlcon.Open();

            sqlcmd.ExecuteNonQuery();

            sqlcon.Close();

        }

        protected void sec4_CheckedChanged(object sender, EventArgs e)
        {
            string soruID = Request.QueryString["soruID"];
            string sinavID = Request.QueryString["sinavID"];
            string userID = Session["userID"].ToString();

            SqlConnection sqlcon = connection.baglanti;
            SqlCommand sqlcmd = new SqlCommand("update cevaplar set cevap=@cevap where soruID=@soruID and sinavID=@sinavID and userID=@userID", sqlcon);
            sqlcmd.Parameters.AddWithValue("@cevap", sec4.Text);
            sqlcmd.Parameters.AddWithValue("@soruID", soruID);
            sqlcmd.Parameters.AddWithValue("@sinavID", sinavID);
            sqlcmd.Parameters.AddWithValue("@userID", userID);

            sqlcon.Open();

            sqlcmd.ExecuteNonQuery();

            sqlcon.Close();

        }
    }
}